package com.wm.service.impl;

import java.util.List;


import javax.annotation.Resource;

import cn.itcast.bean.Person;

import com.wm.bean.Dish;
import com.wm.bean.Restaurant;
import com.wm.dao.DishDao;
import com.wm.dao.RestaurantDao;
import com.wm.service.DishService;
import com.wm.service.RestaurantService;
import com.wm.vo.RestaurantListVO;

public class RestaurantServiceImpl implements RestaurantService {
	@Resource private RestaurantDao restaurantDao;
	
	
	public RestaurantListVO listRestaurants(RestaurantListVO restaurantListVO) {
		int maxResults = 10;
		int beginNum = (restaurantListVO.requestPage-1)*maxResults;
//System.out.println("beginNum="+beginNum);
		
		restaurantListVO.totalPage = restaurantDao.getRestPages(maxResults,restaurantListVO.uid);
		if (restaurantListVO.requestPage > restaurantListVO.totalPage ||restaurantListVO.requestPage < 0) {
			beginNum = 0;
			restaurantListVO.requestPage = 1;
		}
//		System.out.println("beginNum="+beginNum);
		restaurantListVO.restaurantsList = restaurantDao.getRestaurants(beginNum,maxResults,restaurantListVO.uid);
		return restaurantListVO;
	}
	/**
	 
	*/

	public void addResturant(Restaurant restaurant) {
		restaurantDao.save(restaurant);
		
	}
	public List<Restaurant> getRestByHql(String uid) {
		return restaurantDao.getRestaurantsByNameHql(0, 6, "from Restaurant r where r.uid = '"+uid+"'");
		 
	}


}
